package main

import (
	"fmt"
	"image"
	"image/color"
	"image/jpeg"
	"log"
	"math/rand"
	"os"
	"study/test2/captcha"
)

const (
	iw = 40
	ih = 30
	w  = 5
	h  = 8
)

func main() {

	file, err := os.Create("test.png")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()
	rgba := image.NewNRGBA(image.Rect(0, 0, iw, ih))
	codes := []byte{5, 3, 8, 1}
	for i, v := range codes {
		cc := captcha.Font[v]
		for y := 0; y < h; y++ {
			for x := 0; x < w; x++ {
				if cc[y*w+x] != 1 {
					continue
				}
				color := &color.NRGBA{
					uint8(rand.Intn(256)),
					uint8(rand.Intn(256)),
					uint8(rand.Intn(256)),
					0xFF,
				}
				rgba.Set(x+i*10, y+10, color)
			}
		}
		fmt.Println(i)
	}

	jpeg.Encode(file, rgba, nil) //将image信息存入文件中
}
